/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Animation.Animations;

import Scenery.BaseSprite;
import com.jme3.math.Vector3f;
import Animation.Animation;
import Animation.Animation;
import Scenery.BaseCharacter;
import Scenery.BaseSprite;

/*
 *
 * @author usuario
 * 
 */

public class HeadBob extends Animation {


    public HeadBob(BaseCharacter s, int frame) {
        super(s, 20);
        buildAnimation();
    }
    
    private Vector3f head;
    private float headY = 0f;
    private float headYariation = 0.1f;
    private int headUp = 1;
    private float headSpeed = (headYariation * 2) / 5;
    private float iniY = 0;

    @Override
    public void gotoInitialState() {
        headY = 0f;
        headYariation = 0.1f;
        headUp = 1;
        frame = 0;
        headSpeed = (headYariation * 2) / 5;
        animationBody.getHead().setLocalTranslation(head);
    }

    @Override
    public String getName() {
        return "HeadBob";
    }

    @Override
    public void saveInitialState() {
        head = animationBody.getHead().getLocalTranslation().clone();
        iniY = animationBody.getHead().getLocalTranslation().y;
    }

    @Override
    protected void buildFrame() {
         if(frame  < maxFrame/4)
               headY = headSpeed;
           else if(frame >= maxFrame/4 && frame < (maxFrame*3)/4)
               headY = -headSpeed;
           else if(frame >= (maxFrame*3)/4)
               headY = headSpeed;
           animationFrames[frame][0] = headY;
    }

    @Override
    public void performFrame() {
        animationBody.getHead().getLocalTranslation().addLocal(new Vector3f(0, animationFrames[frame][0] ,0));
    }

    @Override
    protected float getCicleRunTime() {
       return 0f;
       
    }
}
